@extends('shop::layouts.master')
@section('title')
    {{$title}}
@endsection
@section('tab')
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form"  lay-filter="form_edit">
                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red">*</span>可结算金额</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" value="{{$arr_data['can_settle_money']}}" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_alias" class="layui-form-label">
                        <span class="x-red">*</span>收款账户类型</label>
                    <div class="layui-input-inline">
                        <select name="in_account_type" lay-filter="form_account_type_select">
                            @foreach($arr_account_type as $key=>$value)
                                <option value="{{$key}}">{{$value}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div id="ali" style="display: none">
                    <div class="layui-form-item">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>支付宝账号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="in_ali_account" value="" autocomplete="off" class="layui-input" maxlength="50">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>户主姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="in_ali_account_realname" value="" autocomplete="off" class="layui-input" maxlength="50">
                        </div>
                    </div>

                </div>

                <div id="bank" style="display: none">
                    <div class="layui-form-item">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>银行名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="in_bank" value="" autocomplete="off" class="layui-input" maxlength="50">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>支行名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="in_bank_branch" value="" autocomplete="off" class="layui-input" maxlength="50">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>银行卡号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="in_bank_card" value="" autocomplete="off" class="layui-input" maxlength="50">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>户主姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="in_bank_card_realname" value="" autocomplete="off" class="layui-input" maxlength="50">
                        </div>
                    </div>
                </div>




                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="form_submit_edit" lay-submit="">添加</button>
                </div>
            </form>
        </div>
    </div>
@endsection

@section('tab_js')
    <script>
        $(function () {
            var account_type = "{{$arr_data['in_account_type']}}";
            var ID_ali = $('#ali');
            var ID_bank = $('#bank');

            ID_ali.hide();
            ID_bank.hide();
            if(account_type === 'ali'){
                ID_bank.hide();
                ID_ali.show();
            }

            if(account_type === 'bank'){
                ID_ali.hide();
                ID_bank.show();
            }

        });
        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //监听提交
            form.on('submit(form_submit_edit)', function (data) {
                var form_field = data.field;
                var in_account_type = form_field.in_account_type;

                if(in_account_type === 'ali'){
                    form_field.in_bank = '';
                    form_field.in_bank_branch = '';
                    form_field.in_bank_card = '';
                    form_field.in_bank_card_realname = '';
                    if(form_field.in_ali_account.length <= 0){
                        layer.msg('请输入支付宝账号');
                        return false;
                    }
                    if(form_field.in_ali_account_realname.length <= 0){
                        layer.msg('请输入支付宝户主姓名');
                        return false;
                    }

                }
                else {
                    form_field.in_ali_account = '';
                    form_field.in_ali_account_realname = '';

                    if(form_field.in_bank.length <= 0){
                        layer.msg('请输入银行名称');
                        return false;
                    }
                    if(form_field.in_bank_branch.length <= 0){
                        layer.msg('请输入支行名称');
                        return false;
                    }
                    if(form_field.in_bank_card.length <= 0){
                        layer.msg('请输入银行卡号');
                        return false;
                    }
                    if(form_field.in_bank_card_realname.length <= 0){
                        layer.msg('请输入银行户主姓名');
                        return false;
                    }
                }

                $.ajax({
                    url: js_url('shop_account_settle_coupon_add'),
                    type: 'post',
                    data: form_field,
                    dataType: "json",
                    success: function (result) {

                        if (result.state === 0) {
                            layer.msg(result.msg, {time: 600, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 600, icon: 5});
                        }
                    }
                });
                return false;
            });

            /*下拉框变动*/
            form.on('select(form_account_type_select)', function(data){
                var account_type = data.value;
                var ID_ali = $('#ali');
                var ID_bank = $('#bank');
                if(account_type === 'ali'){
                    ID_bank.hide();
                    ID_ali.show();
                }
                else{
                    ID_ali.hide();
                    ID_bank.show();
                }
            });

            //表单初始赋值
            var data = {
                in_account_type:"",
                in_ali_account:"{{$arr_data['ali_account']}}",
                in_ali_account_realname:"{{$arr_data['ali_account_realname']}}",
                in_bank:"{{$arr_data['bank']}}",
                in_bank_branch:"{{$arr_data['bank_branch']}}",
                in_bank_card:"{{$arr_data['bank_card']}}",
                in_bank_card_realname:"{{$arr_data['bank_card_realname']}}",
            };
            form.val('form_edit', data)

        });

    </script>
@endsection